home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / chatwins.lzh / chatwin.c next >
C/C++ Source or Header  |  1994-10-14  |  5KB  |  232 lines

  1. /*    Copyright 1993 H.Ogasawara (COR.)    */
  2.  
  3. #include    <corlib.h>
  4.  
  5. #define        MAXCHAR        160
  6. #define        FONT        12
  7. #define        Ctrl(a)        ((a)&0x1f)
  8.  
  9. short    font= FONT,
  10.     fontx= FONT/2,
  11.     attr= 9,
  12.     crmode= 1;
  13. int    usercode= UserPaste;
  14. short    maxchar= MAXCHAR;
  15. int    WindowHeapSize= 1024*8;
  16. char    progname[30],
  17.     header[30];
  18.  
  19. static char    *username[]= {
  20.         "UserPaste", "UserString", "UserStrings", "UserSheet" };
  21.  
  22. send_k20string( msg, cr )
  23. char    *msg;
  24. {
  25.     EventInfo    info;
  26.     if( cr )
  27.         strcat( msg, "\r\0Copyright 1993-94 H.Ogasawara (COR.)" );
  28.     info.option= EventUser;
  29.     info.ComData= usercode;
  30.     info.ComBuffer= msg;
  31.     PidSendEvent( progname, &info, TRUE );
  32. }
  33.  
  34. pos_set( wp, input )
  35. WindowID    wp;
  36. InputClass    *input;
  37. {
  38.     int    x, y, h;
  39.     int    cur= InputGetCursor(input)*fontx;
  40.     WindowGetHome( wp, &x, &y );
  41.     WindowGetViewSize( wp, &h, &y );
  42.     if( cur >= x+h-font ){
  43.         WindowScroll( wp, cur-x-h+12+8*fontx, 0 );
  44.         return    TRUE;
  45.     }else if( cur < x ){
  46.         WindowScroll( wp, cur-x-8*fontx, 0 );
  47.         return    TRUE;
  48.     }
  49.     return    FALSE;
  50. }
  51.  
  52. init_input( wp, ibuf, input )
  53. WindowID    wp;
  54. char    *ibuf;
  55. InputClass    *input;
  56. {
  57.     strcpy( ibuf, header );
  58.     InputSet( input, 0, 0, ibuf, maxchar, attr, font );
  59.     golast_input( wp, ibuf, input );
  60. }
  61.  
  62. golast_input( wp, ibuf, input )
  63. WindowID    wp;
  64. char        *ibuf;
  65. InputClass    *input;
  66. {
  67.     InputSetCursor( input, strlen( ibuf ) );
  68.     if( !pos_set( wp, input ) )
  69.         input_redraw( wp, input );
  70. }
  71.  
  72. input_redraw( wp, input )
  73. WindowID    wp;
  74. InputClass    *input;
  75. {
  76.     DrawBuf    dbuf[20];
  77.     DrawSetClear( dbuf, attr&AttrReverse?attr&3:0 );
  78.     WindowDraw( wp, dbuf, 1+InputSetDraw( dbuf+1, input ) );
  79. }
  80.  
  81. Exec( wp, info )
  82. WindowID    wp;
  83. EventInfo    *info;
  84. {
  85.     DrawBuf        dbuf[20];
  86.     static InputClass    input;
  87.     static char    ibuf[MAXCHAR+4];
  88.     static short    histflag= FALSE;
  89.     int    i;
  90.     switch( info->option ){
  91.     case EventOpen:
  92.         init_input( wp, ibuf, &input );
  93.         return    FALSE;
  94.     case EventRedraw:
  95.         input_redraw( wp, &input );
  96.         return    TRUE;
  97.     case EventMouseSwitch:
  98.         if( info->LeftON ){
  99.             SendData( WindowGetParent(wp), info, UserString, ibuf );
  100.             return    TRUE;
  101.         }
  102.         break;
  103.     case EventMouseEnter:
  104.     case EventMouseOut:
  105.         WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &input,
  106.                 info->option == EventMouseEnter ) );
  107.         return    TRUE;
  108.     case EventKey:
  109.         i= 0;
  110.         switch( info->KeyCode ){
  111.         case Ctrl('e'):
  112.             if( InputGetMode() )
  113.                 goto    Nfunc;
  114.             goto    up_history;
  115.         case Ctrl('p'):
  116.             if( !InputGetMode() )
  117.                 goto    Nfunc;
  118.         case FuncKeyRollDown:
  119.         case Ctrl('w'):
  120.         up_history:
  121.             i= 1;
  122.         case FuncKeyRollUp:
  123.         case Ctrl('x'):
  124.         case Ctrl('n'):
  125.             getnexthist( ibuf, histflag, i );
  126.             golast_input( wp, ibuf, &input );
  127.             histflag= TRUE;
  128.             return    TRUE;
  129.         case '\r':
  130.             i= crmode;
  131.         case '\n': {
  132.             int    x, y;
  133.             histflag= FALSE;
  134.             addhist( ibuf );
  135.             send_k20string( ibuf, i );
  136.             init_input( wp, ibuf, &input );
  137.             WindowGetHome( wp, &x, &y );
  138.             if( x )
  139.                 WindowScroll( wp, -maxchar*fontx+100, 0 );
  140.             }
  141.             return    TRUE;
  142.         default:
  143.             if( info->KeyCode >= FuncKey+1 &&
  144.                     info->KeyCode <= FuncKey+20 ){
  145.                 keyinput( wp, info->KeyCode-FuncKey-1 );
  146.                 return    TRUE;
  147.             }
  148.             histflag= FALSE;
  149.         case Ctrl('a'):
  150.         case Ctrl('q'):
  151.         Nfunc:
  152.             WindowDraw( wp, dbuf,
  153.                 InputKey( dbuf, &input, info->KeyCode,
  154.                             info->ShiftStat ) );
  155.             pos_set( wp, &input );
  156.         }
  157.         return    TRUE;
  158.     }
  159.     return    FALSE;
  160. }
  161.  
  162.  
  163. WindowMain( argc, argv )
  164. char    **argv;
  165. {
  166.     int    i;
  167.     char    *title= "ChatWin v1.21";
  168.     strcpy( progname, "k20.win" );
  169.     *header= '\0';
  170.     for( i= 0 ; i< argc ; i++ ){
  171.         if( *(argv[i]) == '-' ){
  172.             switch( argv[i][1] ){
  173.             case 't':
  174.                 title= argv[i]+2;
  175.                 break;
  176.             case 'c':
  177.                 crmode= 0;
  178.                 break;
  179.             case 'a':
  180.                 attr= atoi2( argv[i]+2 );
  181.                 break;
  182.             case 'm':
  183.                 strcpy( header, argv[i]+2 );
  184.                 break;
  185.             case 'p':
  186.                 strcpy( progname, argv[i]+2 );
  187.                 break;
  188.             case 'r':
  189.                 if( !read_fncfile( argv[i]+2 ) ){
  190.                     ConsoleOpen();
  191.                     ConsolePrint( "chatwin:ファンクションキーファイルが読めません\r\n" );
  192.                 }
  193.                 break;
  194.             case 'f':
  195.                 fontx= (font= atoi2(argv[i]+2))/2;
  196.                 if( fontx == 5 )
  197.                     maxchar= MAXCHAR;
  198.                 else if( fontx == 12 )
  199.                     maxchar= 82;
  200.                 else if( fontx == 8 )
  201.                     maxchar= 120;
  202.                 else
  203.                     maxchar= MAXCHAR,
  204.                     fontx= (font= FONT)/2;
  205.                 break;
  206.             case 'u':
  207.                 {
  208.                 int    j;
  209.                 char    *p= argv[i]+2;
  210.                 for( j= 0 ; j< 4 ; j++ ){
  211.                     if( !strcmp(p,username[j]) ){
  212.                         usercode= j;
  213.                         break;
  214.                     }
  215.                 }
  216.                 if( j == 4 ){
  217.                     if( *p >= '0' && *p <= '9' )
  218.                         usercode= atoi2(p);
  219.                     else for( usercode= 0 ; *p ;
  220.                         usercode<<=8,
  221.                         usercode+= *p++ );
  222.                 }
  223.                 }
  224.                 break;
  225.             }
  226.         }
  227.     }
  228.     MgWindowScrollOpenArgs( 100, 100, 80*6+14, 14+font, title,
  229.             argc, argv, maxchar*fontx, font, Icon|Zoom, Exec );
  230. }
  231.  
  232.